import typing as T
from langchain_core.documents import Document
from typing_extensions import override
from io import BytesIO
from pathlib import Path
from . import IFileLoader, bytesParser


class PDFLoader(IFileLoader):
    def __init__(self):
        self.parser = bytesParser.convert

    @override
    def load(
        self,
        blob: T.Union[str, Path, bytes, BytesIO],
        uuid: str,
        file_name: str = None,
        **kwargs,
    ) -> T.List[Document]:
        self.setUuid(uuid)
        blob = self.verify(blob)
        text = self.parser(blob).text_content
        return [
            Document(
                page_content=text,
                metadata={"file_name": file_name, "type": "pdf", "uuid": uuid},
            )
        ]
